Total Complexity | 2 |
Total Lines | 25 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import {QueryHandler} from '@nestjs/cqrs'; |
||
8 | |||
9 | @QueryHandler(GetCustomerByIdQuery) |
||
10 | export class GetCustomerByIdQueryHandler { |
||
11 | constructor( |
||
12 | @Inject('ICustomerRepository') |
||
13 | private readonly customerRepository: ICustomerRepository |
||
14 | ) {} |
||
15 | |||
16 | public async execute(query: GetCustomerByIdQuery): Promise<CustomerView> { |
||
17 | const customer = await this.customerRepository.findOneById(query.id); |
||
18 | if (!customer) { |
||
19 | throw new CustomerNotFoundException(); |
||
20 | } |
||
21 | |||
22 | const address = customer.getAddress(); |
||
23 | |||
24 | return new CustomerView( |
||
25 | customer.getId(), |
||
26 | customer.getName(), |
||
27 | new AddressView( |
||
28 | address.getId(), |
||
29 | address.getStreet(), |
||
30 | address.getCity(), |
||
31 | address.getZipCode(), |
||
32 | address.getCountry() |
||
33 | ) |
||
37 |